<?php

class Core_Model_Permission_Collection_Action extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('permission/action');
        $this->from('{t}permission_action', 'a')
			 ->field('a.*')
			 ->asc('a.code');
    }
    
    public function joinRole(){
    	return $this->innerJoin('{t}permission_role_action', 'b', 'b.action_id', 'a.id')
    				->innerJoin('{t}permission_role', 'c', 'b.role_id', 'c.id');
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'enabled':
            	return $this->eq('a.status', "'enabled'");
            case 'disabled':
            	return $this->eq('a.status', "'disabled'"); 
            case 'roleid':
            	return $this->eq('b.role_id', ':roleId:i')->addParameter('roleId', $arg);     
			case 'roleids':
            	return $this->contain('b.role_id', ':roleIds:i')->addParameter('roleIds', $arg);   
        }
        return $this;
    }

}